package template;

import com.fh.controller.system.weixin.wxutil.HttpClientUtils;

import java.util.HashMap;
import java.util.Map;



public class TemplateMes {

	// 验证码下发通知
	private static String CAPTCHA = "C6prQJL-_B0WXTEg6tEzFOhYAF7XTx3MQkGm8AqNgX4";
	// 微信绑定成功通知
	private static String BINDINGSUCC = "G9ZAmT7dlrdhj2erL9oXIyoghNiAAwTaBwVgJ2NUauA";
	// 订单状态更新
	private static String UPDATEORDER = "J-_E4A7R3y_m_b3Qh0X2OzIuAjxoI1BOGPX7uuCJtoU";
	// 找回密码通知
	private static String FINDPWD = "K0S1umgygvbJ1UwWbzGyONIOFGckae_eT2hdxY4bts0";
	// 领取红包通知
	private static String RECEIVERED = "Zoi2Hmbm0vl8InrxewOYNsIP346WZE6Qi6nM21YJKiA";
	// 订单支付成功
	private static String PAYSUCC = "_AHJzOER3yJb3Vf43vWpw3Id76QwE9oZ6_3cDH8qGRM";
	// 订单签收提醒
	private static String RECEIPTORDER = "mqHiKAQ5D5o6VWlzkEXcnHhnyuFsoB1LE9wemKOwy_Q";

	private static String MESSAGE_TYPE_CAPTCHA = "Mh40Kj6RQUNqvLv7sLo9akiqln6vjGYd5hFHLhbAFy8";
	private static String MESSAGE_TYPE_BINDINGSUCC = "bindingsucc";
	private static String MESSAGE_TYPE_UPDATEORDER = "updateorder";
	private static String MESSAGE_TYPE_FINDPWD = "findpwd";
	private static String MESSAGE_TYPE_RECEIVERED = "receivered";
	private static String MESSAGE_TYPE_PAYSUCC = "paysucc";
	private static String MESSAGE_TYPE_RECEIPTORDER = "receiptorder";

	public String sendWXMes(String type, Map<String, String> mesinfo)
			throws Exception {
		String jsoninfo = null;
		if (MESSAGE_TYPE_CAPTCHA.equals(type.trim())) {
			// 验证码下发通知
			jsoninfo = TemplateMes.sendCaptcha(mesinfo);
		} else if (MESSAGE_TYPE_BINDINGSUCC.equals(type.trim())) {
			// 微信绑定成功通知
			jsoninfo = TemplateMes.sendBindingsucc(mesinfo);
		} else if (MESSAGE_TYPE_UPDATEORDER.equals(type.trim())) {
			// 订单状态更新
			jsoninfo = TemplateMes.sendUpdateorder(mesinfo);
		} else if (MESSAGE_TYPE_FINDPWD.equals(type.trim())) {
			// 找回密码通知
			jsoninfo = TemplateMes.sendFindpwd(mesinfo);
		} else if (MESSAGE_TYPE_RECEIVERED.equals(type.trim())) {
			// 领取红包通知
			jsoninfo = TemplateMes.sendReceivered(mesinfo);
		} else if (MESSAGE_TYPE_PAYSUCC.equals(type.trim())) {
			// 订单支付成功
			jsoninfo = TemplateMes.sendPaysucc(mesinfo);
		} else if (MESSAGE_TYPE_RECEIPTORDER.equals(type.trim())) {
			// 订单签收提醒
			jsoninfo = TemplateMes.sendReceiptorder(mesinfo);
		}
		String strUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=8_3VbfFmMZKpFoyv4IXvKt16_FPTs31bNfpNgUzc8cofaVcDeM-NxSkl6CsA-UV_BnCWhtR8xhshGe2TOatIXARdwOIVOYXTgYa8NNjVaeedNF8pallSjr42-kZD3Dd-tP9Z9uIwHs7YRjqUJCGZUjAAARKF";
//				+ TokenThread.accessToken.getToken();

		return HttpClientUtils.postJSON(strUrl, jsoninfo);

	}

	private static String sendCaptcha(Map<String, String> mesinfo) {
		String jsoninfo = "{\"template_id\": \""+CAPTCHA+"\",\"topcolor\": \"#FF0000\",\"touser\": \""+mesinfo.get("openid")+"\",\"url\": \""+mesinfo.get("url")+"\", "
				+ "\"data\":"
				+ "{\"first\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("first")+"\" },\"remark\": {\"color\": \"#173177\",\"value\":\""+mesinfo.get("remark")+"\"}, "
				+ "\"number\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("number")+"\" }}}";
		return jsoninfo;
	}

	private static String sendBindingsucc(Map<String, String> mesinfo) {
		String jsoninfo = "{\"template_id\": \""+BINDINGSUCC+"\",\"topcolor\": \"#FF0000\",\"touser\": \""+mesinfo.get("openid")+"\",\"url\": \""+mesinfo.get("url")+"\", "
				+ "\"data\":"
				+ "{\"first\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("first")+"\" },\"remark\": {\"color\": \"#173177\",\"value\":\""+mesinfo.get("remark")+"\"},"
				+ " \"keyword1\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("wechatid")+"\"},"
				+ "\"keyword2\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("bindid")+"\"},"
				+ "\"keyword3\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("features")+"\" }}}";
		return jsoninfo;
	}

	private static String sendUpdateorder(Map<String, String> mesinfo) {
		String jsoninfo = "{\"template_id\": \""+UPDATEORDER+"\",\"topcolor\": \"#FF0000\",\"touser\": \""+mesinfo.get("openid")+"\",\"url\": \""+mesinfo.get("url")+"\", "
				+ "\"data\":"
				+ "{\"first\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("first")+"\" },\"remark\": {\"color\": \"#173177\",\"value\":\""+mesinfo.get("remark")+"\"},"
				+ " \"OrderSn\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("ordersn")+"\"},"
				+ "\"OrderStatus\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("orderstatus")+"\" }}}";
		return jsoninfo;
	}

	private static String sendFindpwd(Map<String, String> mesinfo) {
		String jsoninfo = "{\"template_id\": \""+FINDPWD+"\",\"topcolor\": \"#FF0000\",\"touser\": \""+mesinfo.get("openid")+"\",\"url\": \""+mesinfo.get("url")+"\", "
				+ "\"data\":"
				+ "{\"first\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("first")+"\" },\"remark\": {\"color\": \"#173177\",\"value\":\""+mesinfo.get("remark")+"\"},"
				+ " \"keyword1\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("username")+"\"},"
				+ "\"keyword2\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("password")+"\" }}}";
		return jsoninfo;
	}

	private static String sendReceivered(Map<String, String> mesinfo) {
		String jsoninfo = "{\"template_id\": \""+RECEIVERED+"\",\"topcolor\": \"#FF0000\",\"touser\": \""+mesinfo.get("openid")+"\",\"url\": \""+mesinfo.get("url")+"\", "
				+ "\"data\":"
				+ "{\"first\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("first")+"\" },\"remark\": {\"color\": \"#173177\",\"value\":\""+mesinfo.get("remark")+"\"},"
				+ " \"keyword1\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("redEnvelope")+"\"},"
				+ "\"keyword2\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("amount")+"\" }}}";
		return jsoninfo;
	}

	private static String sendPaysucc(Map<String, String> mesinfo) {
		String jsoninfo = "{\"template_id\": \""+PAYSUCC+"\",\"topcolor\": \"#FF0000\",\"touser\": \""+mesinfo.get("openid")+"\",\"url\": \""+mesinfo.get("url")+"\", "
				+ "\"data\":"
				+ "{\"first\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("first")+"\" },\"remark\": {\"color\": \"#173177\",\"value\":\""+mesinfo.get("remark")+"\"},"
				+ " \"orderMoneySum\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("orderMoneySum")+"\"},"
				+ "\"orderProductName\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("orderProductName")+"\" }}}";
		return jsoninfo;
	}

	private static String sendReceiptorder(Map<String, String> mesinfo) {
		String jsoninfo = "{\"template_id\": \""+RECEIPTORDER+"\",\"topcolor\": \"#FF0000\",\"touser\": \""+mesinfo.get("openid")+"\",\"url\": \""+mesinfo.get("url")+"\", "
				+ "\"data\":"
				+ "{\"first\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("first")+"\" },\"remark\": {\"color\": \"#173177\",\"value\":\""+mesinfo.get("remark")+"\"},"
				+ " \"Content1\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("content")+"\"},"
				+ " \"Good\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("good")+"\"},"
				+ " \"OrderSn1\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("ordersn1")+"\"},"
				+ " \"OrderSn2\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("ordersn2")+"\"},"
				+ " \"OrderSn3\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("ordersn3")+"\"},"
				+ "\"Eval\": {\"color\": \"#173177\",\"value\": \""+mesinfo.get("eval")+"\" }}}";
		return jsoninfo;
	}
	public static void main(String[] args) {
		TemplateMes wm=new TemplateMes();
		String type="receiptorder";//换这里测试
		Map<String, String> mesinfo = new HashMap<String, String>();
		mesinfo.put("openid", "oV_bU1Q64Auw0xKwbbayI8xYQUPg");//微信openid
		mesinfo.put("url", "www.baidu.com");//点击以后跳转的链接地址
		if (type.equals("captcha")) {
			/*	验证码下发通知
			 * 	尊敬的顾客，手机动态验证码为123456。
			 *	该验证码有效期30分钟可输入1次，转发无效。
			 */
			mesinfo.put("first", "尊敬的顾客,");
			mesinfo.put("remark", "该验证码有效期30分钟可输入1次，转发无效。");
			mesinfo.put("number", "123456789");
		}else if (type.equals("bindingsucc")) {
			/*	微信绑定成功通知
			 * 	微信账号绑定成功，热烈欢迎 If 与千万少年同享大学新生活！
			 *	微信ID：icefest
			 *	绑定账号：icefest@qq.com
			 *	开通功能：订单动态跟踪、还款提醒、免密登录
			 *	点击查看我的个人中心
			 */
			mesinfo.put("first", "微信账号绑定成功，热烈欢迎 If 与千万少年同享大学新生活！");
			mesinfo.put("remark", "点击查看我的个人中心");
			mesinfo.put("wechatid", "icefest");
			mesinfo.put("bindid", "icefest@qq.com");
			mesinfo.put("features", "订单动态跟踪、还款提醒、免密登录");
		}else if (type.equals("updateorder")) {
			/*	订单状态更新
			 * 	尊敬的kant:
			 *	订单编号: 1130927196009757
			 *	订单状态: 已收货
			 *	物流信息: 圆通速递(上海)
			 *	快递单号: 8031971890
			 */
			mesinfo.put("first", "尊敬的kant:");
			mesinfo.put("remark", " 圆通速递(上海)快递  \\n单号: 8031971890 ");
			mesinfo.put("ordersn", "1130927196009757");
			mesinfo.put("orderstatus", "已收货");
		}else if (type.equals("findpwd")) {
			/*	找回密码通知
			 * 	你在StarCraft官网的登录信息如下：
			 *	登录帐号：zeratul@starcraft.com
			 *	密码：zeratul/ttnn-20140821
			 *	请妥善保管
			 */
			mesinfo.put("first", "你在StarCraft官网的登录信息如下：");
			mesinfo.put("remark", "请妥善保管");
			mesinfo.put("username", "zeratul@starcraft.com");
			mesinfo.put("password", "zeratul/ttnn-20140821");
		}else if (type.equals("receivered")) {
			/*	领取红包通知
			 * 	去哪儿红包来啦！
			 *	成功领取：去哪儿网发的酒店红包（1个）
			 *	红包金额：1元
			 *	红包可用于预订酒店，成功入住并离店后返还给您与红包等额的现金
			 */
			mesinfo.put("first", "去哪儿红包来啦！");
			mesinfo.put("remark", "红包可用于预订酒店，成功入住并离店后返还给您与红包等额的现金");
			mesinfo.put("redEnvelope", "去哪儿网发的酒店红包（1个）");
			mesinfo.put("amount", "1元");
		}else if (type.equals("paysucc")) {
			/*	订单支付成功
			 *	订单号：12345678
			 *	支付金额：30.00元
			 *	商品信息：我是商品名字
			 *	预计送达：2013年11月11日下午
			 */
			mesinfo.put("first", "订单号：12345678");
			mesinfo.put("remark", "预计送达：2013年11月11日下午");
			mesinfo.put("orderMoneySum", "30.00元");
			mesinfo.put("orderProductName", "我是商品名字");
		}else if (type.equals("receiptorder")) {
			/*	订单签收提醒
			 *	尊敬的用户，您好
			 *	您购买的海尔冰箱已经准备配送，签收信息如下:
			 *	商品名称：海尔冰箱
			 *	好评签收码：113412
			 *	中评签收码：223424
			 *	差评签收码：333445
			 *	监督评价：http://www.rrs.com/
			 *	友情提醒：请确认收货后根据实际服务情况进行签收
			 */
			mesinfo.put("first", "你好");
			mesinfo.put("content", "测试信息");

		}
		try {
			String res=	wm.sendWXMes(type, mesinfo);
			System.out.println(res);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


}
